#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "std_msgs/Bool.h"

#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>

int flag;
ros::NodeHandle nh;
ros::Publisher over = nh.advertise<std_msgs::Bool>("finish_application", 1000);

void nav_speak_cb(const std_msgs::Bool::ConstPtr& msg)
{
    std_msgs::Bool jug;
    jug.data = 1;
    if(msg->data == jug.data){
        unlink("/tmp/cmd");
        mkfifo("/tmp/cmd", 0777);
        popen("mplayer -quiet -slave -input file=/tmp/cmd 'test.wav'","r");
        sleep(9000);
        std_msgs::Bool a;
        a.data = true;
        over.publish(a);
    }
}

int main(int argc, char * argv[])
{
    ros::init(argc, argv, "nav_speak");
    ros::NodeHandle n;
    ros::Subscriber nav_speak_sub = n.subscribe("start_application", 1000, nav_speak_cb);

    //if()*/
    ros::spin();
    return 0;
}
